//
//  SelectViewController.m
//  CarFace
//
//  Created by dlios on 15-3-24.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "SelectViewController.h"
#import "UIButton+InitButton.h"
@interface SelectViewController ()<UIWebViewDelegate>
@property(nonatomic, retain)UIView *viewSele;
@property(nonatomic, retain)UIView *pushView;
@end

@implementation SelectViewController
- (void)dealloc
{
    [_foruF release];
    [_viewSele release];
    [super dealloc];
}

- (void)datahander
{
    CGFloat width = self.view.frame.size.width;
    CGFloat height = self.view.frame.size.height;
    NSString *ipS = self.foruF.topicid;
    NSString *str = @"http://forum.app.autohome.com.cn/autov4.6/forum/club/topiccontent-a2-pm2-v4.6.0-t39708821-o0-p1-s20-c1-nt0-fs1-sp0-al0-cw320.json";
    
    NSString *strIp = [str stringByReplacingOccurrencesOfString:@"39708821" withString:ipS];
    
    NSURL *url = [NSURL URLWithString:strIp];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 50, width, height - 50)];
    webView.delegate = self;
    webView.scalesPageToFit = YES;
    [webView loadRequest:request];
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    [self.viewSele addSubview:webView];
    [webView release];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.viewSele = [[UIView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:self.viewSele];
    [_viewSele release];
    [self datahander];
    
    //  顶部实现
    CGFloat width = self.viewSele.frame.size.width;
//    CGFloat height = self.viewSele.frame.size.height;
    UIButton *returnButton = [UIButton buttonWithTitle:@"返回" frame:CGRectMake(0, 20, width / 4,20) target:self action:@selector(clickReturnButton:)];
    [returnButton setImage:[UIImage imageNamed:@"iconfont-fanhui.png"] forState:UIControlStateNormal];
    [returnButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.viewSele addSubview:returnButton];

////    底部实现
//    UIButton *pageButton = [UIButton buttonWithTitle:@"1/40页" frame:CGRectMake(width - 80, height - 35, 60, 30) target:self action:@selector(clickPageButton:)];
//    [pageButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [self.viewSele addSubview:pageButton];
//    [self.view bringSubviewToFront:self.viewSele];
//    
   
    
}

- (void)clickPageButton:(UIButton *)button
{
    
    self.pushView = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height  * 2 / 3, self.view.frame.size.width, self.view.frame.size.height / 3)];
    [self.view addSubview:self.pushView];
    self.pushView.backgroundColor = [UIColor greenColor];
    
    UIButton *cancle = [UIButton buttonWithTitle:@"取消" frame:CGRectMake(5, 2, self.pushView.frame.size.width / 6, self.pushView.frame.size.height / 5) target:self action:@selector(clickCancleButtonAction:)];
    [self.pushView addSubview:cancle];
    cancle.backgroundColor = [UIColor purpleColor];
    
    UIButton *ensure = [UIButton buttonWithTitle:@"确定" frame:CGRectMake(self.pushView.frame.size.width - 2 - self.pushView.frame.size.width / 6, 2, self.pushView.frame.size.width / 6, self.pushView.frame.size.height / 5) target:self action:@selector(clickEnsureButtonAction:)];
    [self.pushView addSubview:ensure];
    ensure.backgroundColor = [UIColor purpleColor];
    [_pushView release];

}



- (void)clickCancleButtonAction:(UIButton *)button
{
//    [self.view bringSubviewToFront:self.aView];
    self.pushView.hidden = YES;
}

- (void)clickEnsureButtonAction:(UIButton *)button
{
    NSLog(@"ggkkk");
}


- (void)clickReturnButton:(UIButton *)button
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
    
}


- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
